<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="mac" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page errorPage="error/404.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="shortcut icon" href="/images/favicon.png">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/layui/layui.all.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend style="text-align: center">${admin.realname}博客</legend>
</fieldset>

<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设置我的基本资料</div>
                <form class="layui-form" id="add">
                    <div class="layui-card-body">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">用户名:</label>
                                <div class="layui-input-inline">
                                <input readonly="readonly" name="aid" value="${admin.aid}" type="hidden"/>
                                    <input  name="username" placeholder="${admin.username}" 
                                           autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <span style="color: #8D8D8D">一般作为后台登入名，不可以更改！</span>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">昵&nbsp;称:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="realname" placeholder="真实姓名" lay-verify="readonly"
                                       autocomplete="off" class="layui-input" value="${admin.realname}">
                            </div>
                          
                        </div>
                             					<br>
     					<br>
     					   <div class="layui-inline">
                            <label class="layui-form-label">密&nbsp;码:</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" placeholder="请输入修改的密码" lay-verify="readonly"
                                       autocomplete="off" class="layui-input" value="${admin.password}">
                            </div>
                          
                        </div>
     					<br>
     					  <br>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">头&nbsp;像:</label>
                                <div class="layui-input-inline">
                                    <input type="file" name="pic" id="test3" placeholder="图片地址" lay-verify="readonly"
                                           autocomplete="off" class="layui-input">
                                           <input type="text" name="photo" placeholder="图片地址" lay-verify="readonly"
                                           autocomplete="off" class="layui-input">
                                            <img alt="" src="?" name="showimg" id="showimg" onerror="this.src='/images/nopic-107.png'; this.title='图片未找到.'"  style="width:100px;height:100px;">
                                            <img alt="" src="${admin.photo}" style="width:50px;height:50px;">
                                </div>
                                <br>
                            </div>
                           
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">手机号:</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="phonenumber" placeholder="请输入手机号" lay-verify="required|phone"
                                       autocomplete="off" class="layui-input" value="${admin.phonenumber}">
                            </div>
                        </div>
                                            
                        <br><br>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">身份证号:</label>
                            <div class="layui-input-inline">
                               
                            <input type="text" name="idcardnum" placeholder="请输入身份证号" lay-verify="required|identity" class="layui-input" value="${admin.idcardnum}"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="/layui/layui.js"></script>
<script>
    //单选按钮
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (res) {
  
  $.ajax({
  url:"/admin/addUser",
  type:"post",
  dataType:"json",
  data:$("#add").serialize(),
  success:function(data){
  if(data.status==200){
   layer.msg("添加成功", {icon: 6}, function(){
						location.href =  "/main.html";
					});
  }else if(data.status==400){
    layer.msg("添加失败", {icon: 5});
  }

  }
  
  
  
  });
         
        });
    });
    //-----------------------------
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;
        //指定允许上传的文件类型
        upload.render({
            elem: '#test3'
            , url: '/upload/pic'
            , accept: 'file' //普通文件
            , done: function (res) {
             alert(res.data.src);
               $("[name=photo]").val(res.data.src);
                 document.getElementById('showimg').src = res.data.src; 
            }
        });
    });
</script>
</body>
</html>